#include "overview.h"
#include "item/imageitem.h"
#include "recource.h"
#include "item/scoreitem.h"
#include "scene/gamescene.h"
#include <QLocale>
enum OverBtn
{
    RESTART_OB,
    BACK_OB,
    NULL_OB,
}overBt(NULL_OB);

overView::overView(QWidget *parent) :
    QGraphicsView(parent)
{
    initItem();
}

overView::~overView()
{
    delete m_Scene;
}

void overView::initItem()
{
    m_Scene = new QGraphicsScene(this);
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setScene(m_Scene);
    m_Scene->setSceneRect(0.0, 0.0, 360.0, 640.0);
    setGeometry(0.0,0.0,360.0,640.0);

    m_bgItem = new ImageItem(*Recource::m_promptbgImage,
                             QRect(QPoint(0,0),Recource::m_promptbgImage->size()));
    m_bgItem->setPos(0.0,0.0);
    m_bgItem->setZValue(0.0);
    m_Scene->addItem(m_bgItem);

    switch(Recource::m_iLanguage)
    {
    case QLocale::Chinese:
    {
        m_mbgItem = new ImageItem(*Recource::m_overBgImage,
                                 QRect(QPoint(0,0),Recource::m_overBgImage->size()));
        m_backItem = new ImageItem(*Recource::m_pauseBackImage,
                                 QRect(QPoint(0,0),Recource::m_pauseBackImage->size()));
        m_restartItem = new ImageItem(*Recource::m_pauseRestartImage,
                                 QRect(QPoint(0,0),Recource::m_pauseRestartImage->size()));
    }
        break;
//    case QLocale::HongKong:
    case 255:
    {
        m_mbgItem = new ImageItem(*Recource::m_overBgHkImage,
                                 QRect(QPoint(0,0),Recource::m_overBgHkImage->size()));
        m_backItem = new ImageItem(*Recource::m_pauseBackHkImage,
                                 QRect(QPoint(0,0),Recource::m_pauseBackHkImage->size()));
        m_restartItem = new ImageItem(*Recource::m_pauseRestartHkImage,
                                 QRect(QPoint(0,0),Recource::m_pauseRestartHkImage->size()));
    }
        break;
    default:
    {
        m_mbgItem = new ImageItem(*Recource::m_overBgEnImage,
                                 QRect(QPoint(0,0),Recource::m_overBgEnImage->size()));
        m_backItem = new ImageItem(*Recource::m_pauseBackEnImage,
                                 QRect(QPoint(0,0),Recource::m_pauseBackEnImage->size()));
        m_restartItem = new ImageItem(*Recource::m_pauseRestartEnImage,
                                 QRect(QPoint(0,0),Recource::m_pauseRestartEnImage->size()));
    }
        break;
    }

    m_mbgItem->setPos(0.0,159.0);
    m_mbgItem->setZValue(0.0);
    m_Scene->addItem(m_mbgItem);

    m_restartItem->setPos(67.0,296.0);
    m_restartItem->setZValue(1.0);
    m_restartItem->setVisible(false);
    m_Scene->addItem(m_restartItem);

    m_backItem->setPos(67.0,376.0);
    m_backItem->setZValue(1.0);
    m_backItem->setVisible(false);
    m_Scene->addItem(m_backItem);

    m_curScore = new ScoreItem(Recource::m_gamescore);
    m_curScore->setZValue(5.0);
    m_curScore->m_x = 295.0;
    m_curScore->setPos(295.0,245.0);
    m_curScore->setNum(Recource::m_gamescene->m_iScore);
    m_Scene->addItem(m_curScore);

    m_highestScore = new ScoreItem(Recource::m_gamescore1);
    m_highestScore->setZValue(5.0);
    m_highestScore->m_x = 295.0;
    m_highestScore->setPos(295.0,195.0);
    switch(Recource::m_gamescene->m_icurlevel)
    {
    case 1:
    {
       m_highestScore->setNum(Recource::m_ilevelScore_1);
    }
    break;
    case 2:
    {
       m_highestScore->setNum(Recource::m_ilevelScore_2);
    }
    break;
    case 3:
    {
       m_highestScore->setNum(Recource::m_ilevelScore_3);
    }
    break;
    default:
        break;
    }
    m_Scene->addItem(m_highestScore);
}

void overView::mousePressEvent(QMouseEvent *event)
{
    if(m_restartItem->isUnderMouse())
    {
        m_restartItem->setVisible(true);
        overBt = RESTART_OB;
    }
    else if(m_backItem->isUnderMouse())
    {
        m_backItem->setVisible(true);
        overBt = BACK_OB;
    }else
    {
        overBt=NULL_OB;
    }
}

void overView::mouseReleaseEvent(QMouseEvent *event)
{
    switch(overBt)
    {
    case RESTART_OB:
    {
        m_restartItem->setVisible(false);
//        if(m_restartItem->isUnderMouse())
            emit back(0);
    }
    break;
    case BACK_OB:
    {
        m_backItem->setVisible(false);
        emit back(1);
    }
    break;
    default:
        break;
    }
}


